package com.example.aircraft.panel;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.CompoundButton;
import android.widget.Switch;

import com.example.aircraft.gamemode.Game;
import com.example.aircraft.gamemode.HardGame;
import com.example.aircraft.MyApplication;
import com.example.aircraft.gamemode.NormGame;
import com.example.aircraft.R;
import com.example.aircraft.base.BGMService;


public class ChoosePattern extends Activity {

    private static final String TAG = "change";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        Intent intent = new Intent(MyApplication.getContext(), BGMService.class);
        super.onCreate(savedInstanceState);
        if(MyApplication.isMusicOn()){
            startService(intent);}
        setContentView(R.layout.activity_choose_pattern);
        @SuppressLint("UseSwitchCompatOrMaterialCode") Switch switch1 =(Switch) findViewById(R.id.switch1) ;
        switch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    Log.d(TAG, "开启音效");
                    MyApplication.setMusicOn();
                    startService(intent);
                }
                else{
                    Log.d(TAG, "关闭音效");
                    MyApplication.setMusicOff();
                    stopService(intent);
                }

            }
        });
    }

    public void chooseEasy(View view) {
        Log.d(TAG,"选择简单模式");
        setContentView(new Game(this));
    }

    public void chooseNormal(View view) {
        Log.d(TAG,"选择普通模式");
        setContentView(new NormGame(this));
    }

    public void chooseHard(View view) {
        Log.d(TAG,"选择困难模式");
        setContentView(new HardGame(this));
    }

    public void backToMenu(View view) {
        Log.d(TAG, "Go Back to Menu: ");
        Intent intent = new Intent(ChoosePattern.this, MenuActivity.class);
        startActivity(intent);
        finish();
    }

    public void checkrank(View view) {
        Intent intent = new Intent(ChoosePattern.this,RankPanel.class);
        startActivity(intent);
        finish();
    }
}